const { http } = require("../../utils/http");

// pages/user/index.js
Page({
  data: {
    h:0,
    userInfo:'',
    collectionNum:0
  },
  onLoad: function (options) {
    var url="http://122.112.245.197:5000/api/collection";
    http({
      url,
      success:(res)=>{
        var collectionNum=0;
        res.data.forEach(item=>{
          if(!wx.getStorageSync('iphone')){
            return false;
          }
          else if(item.userID==wx.getStorageSync('iphone')){
            collectionNum++;
          }
        })
        this.setData({
          collectionNum:collectionNum
        })
      }
    })


    var result = wx.getMenuButtonBoundingClientRect()
    this.setData({h: this.data.h + result.top + result.height});
  },
  goEnrool:function(){
    wx.navigateTo({
      url: '../login/index',
    })
  },
  login(){
    wx.getUserProfile({
      desc: '必须授权才可以使用',
      success:res=>{
          let user=res.userInfo
          console.log("用户信息",user)
          this.setData({
              userInfo:res.userInfo
          })
      },
      fail:res=>{
          console.log('授权失败',res)
      }
    })
        },
    // collectionClick(){
    //   wx.navigateTo({
    //     url: '../../pages/collect/index',
    //   })
    // }
    order(){
      wx.navigateTo({
        url: '../../pages/order/index',
      })
    },
    onShow:function(option){
      this.onLoad();
    }
 
})